<template>
  <div>
    <el-container>
      <el-main>
        <kendoForm
          :kendo-form-items="kendoFormItems"
          :kendo-form="kendoForm"
          :kendo-params-value="kendoParamsValue"
        />
      </el-main>
    </el-container>
    <KendoWindow
      :dialog-title="dialogTitle"
      :components-list="componentsList"
      :operate-dialog-view="operateDialogVisible"
      @beforeClose="beforeClose"
    />
  </div>
</template>

<script>
  import kendoForm from '@/Views/components/kendo-vue-component/kendoForm/index.vue'

  export default {
    name: 'PrjmemberChoiceStaWeek',
    components: {
      kendoForm
    },
    data() {
      return {
        /* com*/
        dialogName: this.$attrs ? (this.$attrs.data ? (this.$attrs.data.dialogName ? this.$attrs.data.dialogName : '') : '') : '',
        operateDialogVisible: false,
        dialogTitle: '',
        componentsList: [],
        /* Form*/
        kendoFormItems: [
          {
            name: 'weeklyWhichMonth',
            label: '周报年月',
            paramName: 'weeklyWhichMonth',
            controlType: 'datePicker',
            required: true,
            step: 'year',
            format: 'yyyy-MM'
          },
          {
            ref: 'WEEK_OF_MONTH_CD',
            remoteData: true,
            name: 'weekOfCurrentMonth',
            label: '周数',
            paramName: 'weekOfCurrentMonth',
            optionLabel: '--请选择--',
            controlType: 'dropDownList',
            required: true,
            filter: 'contains',
            dataType: 'json',
            transportReadUrl: '/service/sysMng/dict/findDictByTypeWithForm',
            autoBind: true,
            schema: {
              data: function(response) {
                return response.data
              }
            },
            dataMapping: {
              label: 'dictValNm',
              value: 'dictVal'
            },
            parameterMap: function(options, operation) {
              if (operation !== 'read' && options.models) {
                // eslint-disable-next-line no-undef
                return { models: kendo.stringify(options.models) }
              } else {
                // eslint-disable-next-line no-undef
                return kendo.stringify({ dict: 'WEEK_OF_MONTH_CD' })
              }
            }
          }
        ],
        kendoForm: {
          ref: 'prjForm',
          valid: 'valid',
          buttons: [
            {
              name: '确定', // 按钮内容
              class: 'k-primary', // 按钮样式
              icon: 'check',
              click: this.check
            }
          ]
        },
        kendoParamsValue: {
          memberNo: '',
          weeklyWhichMonth: '',
          weekOfCurrentMonth: ''
        }
      }
    },
    mounted() {
      const operatorType = this.$attrs.data.operatorType
      const members = {
        name: 'memberNo',
        label: '统计成员',
        paramName: 'memberNo',
        viewDisabled: true,
        controlType: 'multiselect',
        dataSource: 'PrjMemberDataSource',
        dataType: 'json',
        transportReadUrl: '/service/prjMng/prjMemberMng/findPrjMemberList',
        dataMapping: {
          label: 'memberName',
          value: 'memberNo'
        },
        autoBind: true,
        remoteData: true,
        schema: {
          data: function(response) {
            if (typeof response.data === 'object') {
              if (JSON.stringify(response.data) === '{}') {
                return []
              }
            }
            return response.data
          }
        }
      }
      if (operatorType === 'sta') {
        this.kendoFormItems.push(members)
      }
    },
    methods: {
      check(paramVal, validator) {
        if (validator.validate()) {
          const operatorType = this.$attrs.data.operatorType
          let component = {}
          if (operatorType === 'add') {
            component = {
              component: '/projmng/prjmemberweekly/weekly.vue',
              dialogName: this.uid(),
              operatorType: operatorType,
              param: paramVal
            }
            this.dialogTitle = '新增周报'
          } else if (operatorType === 'sta') {
            component = {
              component: '/projmng/prjmemberweekly/statistics.vue',
              dialogName: this.uid(),
              operatorType: operatorType,
              param: paramVal
            }
            this.dialogTitle = '周报统计'
          }
          this.operateDialogVisible = true
          this.componentsList.push(component)
          // this.$bus.emit('dialog' + `${this.dialogName}`, true)
        }
      },
      beforeClose(res) {
        if (res) {
          this.dialogTitle = ''
          this.operateDialogVisible = false
          this.componentsList = []
        }
      }
    }
  }
</script>

<style>

</style>
